import React, { memo, useEffect, useState } from 'react'

const MyUserEffectCallback = memo(() => {
  const [count, setCount] = useState(0)
  
  // 负责告知react, 在执行完当前组件渲染之后要执行的副作用代码
  useEffect(() => {
    console.log('03-MyUserEffectCallback useEffect')
    // document.title = `count: ${count}`

    // 返回值: 回调函数 => 组件被重新渲染或者组件卸载的时候执行
    return () => {
      console.log('03-MyUserEffectCallback 组件卸载')
    }
  })
  
  return (
    <div>
      <button onClick={e => setCount(count+1)}>+1({count})</button>
    </div>
  )
})

export default MyUserEffectCallback